﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using BOHVote.BLL;
using System.Text;

namespace BOH.AccreditationSystem
{
    public partial class PrintInterviewList : System.Web.UI.Page
    {
        string strSubjectID = string.Empty;
        string strApplyPeriodID = string.Empty;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (Session["ApplyPeriod"] != null)
                {
                    //ApplyListDataSet();
                    HasBuildNumber();
                }
                
            }
        }

        public void HasBuildNumber()
        {
            int count = ApplyClass.CountUnBuildNumber((string)Session["ApplyPeriod"], Request.QueryString["Subject"].ToString());
            if (count > 0)
            {
                Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "confirm", "<script>alert('" + (string)Session["ApplyPeriod"] + "年度 学科组【" + Request.QueryString["Subject"].ToString() + "】申报编号未生成! ');window.close();</script>");
            }
            else
            {
                if (Request.QueryString["Subject"] != null)
                {
                    ApplyListDataSet();
                }
            }
        }

        protected void AspNetPager1_PageChanged(object src, EventArgs e)
        {
            ApplyListDataSet();
        }

        public DataSet dstApplyList(string GovernID, string SubjectID, string ApplyPeriod)
        {
            DataSet dst = null;
            string UnitGovrenID = string.Empty;

            dst = ApplyClass.dstApplysForInterview(string.Empty, "-1", "-1", GovernID, "-1", "-1", "-1", SubjectID, "-1", ApplyPeriod);
            DataColumn cl = new DataColumn();
            cl.ColumnName = "isSet";
            dst.Tables[0].Columns.Add(cl);
            DataColumn clTime = new DataColumn();
            clTime.ColumnName = "InterviewDateTime";
            dst.Tables[0].Columns.Add(clTime);

            foreach (DataRow dr in dst.Tables[0].Rows)
            {
                if (!string.IsNullOrEmpty(dr["InterView_Month"].ToString()) && !string.IsNullOrEmpty(dr["InterView_Day"].ToString()) && !string.IsNullOrEmpty(dr["interview_TimeHH"].ToString()) && !string.IsNullOrEmpty(dr["interview_TimeMM"].ToString()))
                {
                    dr["InterviewDateTime"] = dr["InterView_Month"].ToString() + "月" + dr["InterView_Day"].ToString() + "日" + " " + dr["interview_TimeHH"].ToString() + ":" + dr["interview_TimeMM"].ToString();
                }
                else
                {
                    dr["InterviewDateTime"] = string.Empty;
                }
            }
            return dst;
        }

        public void ApplyListDataSet()
        {
            string Subject = Request.QueryString["subject"].ToString();
            string GovernID = Request.QueryString["Govern"].ToString();
            DataSet dst = dstApplyList(GovernID,Subject, (string)Session["ApplyPeriod"]);
            //hidePrintApplyIDList.Value = sbPrintApply.ToString();
            BindApplyList(dst);
        }

        public void BindApplyList(DataSet dst)
        {
            if (dst != null && dst.Tables[0].Rows.Count > 0)
            {
                AspNetPager1.RecordCount = dst.Tables[0].Rows.Count;
                if (AspNetPager1.RecordCount != 0)
                {
                    labNoRecord.Visible = false;
                    AspNetPager1.Visible = true;
                    PagedDataSource pds = new PagedDataSource();
                    pds.DataSource = dst.Tables[0].DefaultView;
                    pds.AllowPaging = true;
                    pds.CurrentPageIndex = AspNetPager1.CurrentPageIndex - 1;
                    pds.PageSize = AspNetPager1.PageSize;
                    labCurrentPage.Text = AspNetPager1.CurrentPageIndex.ToString();
                    labTotlePage.Text = AspNetPager1.PageCount.ToString();
                    labRecord.Text = AspNetPager1.PageSize.ToString();
                    ApplyViewList.DataSource = pds;
                    ApplyViewList.DataBind();
                }
                else
                {
                    ApplyViewList.DataSource = null;
                    ApplyViewList.DataBind();
                    AspNetPager1.Visible = false;
                    labNoRecord.Visible = true;
                }
            }
            else
            {
                AspNetPager1.Visible = false;
                labNoRecord.Visible = true;
                ApplyViewList.DataSource = null;
                ApplyViewList.DataBind();
            }
        }
    }
}
